package com.supermarket.exception;

/**
 * 数据验证异常类
 * 用于处理业务数据验证失败的情况
 */
public class ValidationException extends Exception {
    private String field;
    private Object value;

    public ValidationException(String message) {
        super(message);
    }

    public ValidationException(String message, Throwable cause) {
        super(message, cause);
    }

    public ValidationException(String field, Object value, String message) {
        super(message);
        this.field = field;
        this.value = value;
    }

    public String getField() {
        return field;
    }

    public Object getValue() {
        return value;
    }

    /**
     * 获取用户友好的错误消息
     */
    public String getUserFriendlyMessage() {
        if (field != null) {
            return String.format("字段 '%s' 验证失败: %s", field, getMessage());
        }
        return getMessage();
    }
}